package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.pojo.Waste;
import com.example.mapper.WasteMapper;
import com.example.service.IWasteService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.vo.WasteVo;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lyj
 * @since 2023-02-16
 */
@Service
public class WasteServiceImpl extends ServiceImpl<WasteMapper, Waste> implements IWasteService {

    @Override
    public Page<WasteVo> queryByCondition(Page<WasteVo> page, Map<String, Object> map) {
        QueryWrapper<WasteVo> wrapper = new QueryWrapper<>();
        wrapper.apply(" w.parent_id=wt.id and w.del_flag=0 ")
                .like(!ObjectUtils.isEmpty(map.get("name")), "w.name", map.get("name"))
                .like(!ObjectUtils.isEmpty(map.get("code")), "w.code", map.get("code"))
                .eq(!ObjectUtils.isEmpty(map.get("parentId")), "w.parent_id", map.get("parentId"));
        return baseMapper.queryByCondition(page,wrapper);
    }
}
